package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.SettingOfSecurities;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Tabase;
import sanrenxing.dayEnd.backRepertoryTotal.domain.TabaseT;

import java.util.List;

/**
 * Description:
 * date：2021/3/11 0011 下午 4:37
 * @auther ${梁树仁}
 * @version：
 * @since JDK 1.8
 **/
@Repository
public interface TabaseDao {
    /**
     * 增加一行ta交易数据
     * @param tabaset
     * @returne
     */
    @Insert("insert into taDataTable(dataId,fundId,caId,dates,numbers,endDate,sumMoney,actMoney,price,expenses,conagen,tranType,tranStatus)" +
            "values(#{dataId},#{fundId},#{caId},to_date('${dates}','yyyy-MM-dd'),#{numbers},to_date('${endDate}','yyyy-MM-dd'),#{sumMoney},#{actMoney},#{price},#{expenses},#{conagen},#{tranType},#{tranStatus})")
    public int add(TabaseT tabaset);

    /**
     *删除一行Ta交易数据
     * @param dataId
     * @return
     */
    @Delete("delete from taDataTable where dataId=#{dataId}")
    public int delete(int dataId);

    /**
     * 修改ta交易数据
     * @param tabase
     * @return
     */
    @Update("update taDataTable set fundId=#{fundId},caId=#{caId},dates=#{dates},numbers=#{numbers},endDate=#{endDate},sumMoney=#{sumMoney},actMoney=#{actMoney}," +
            "price=#{price},expenses=#{expenses},conagen=#{conagen},tranType=#{tranType},tranStatus=#{tranStatus} where dataId=#{dataId}")
    public int update(Tabase tabase);

    /**
     * 查询所有
     * @param
     * @return
     */
    @Select("select * from taDataTable")
    @Results(id="tabaseMap",value = {
            @Result(id=true,property = "dataId",column = "dataId"),
            @Result(property = "fundId",column = "fundId"),
            @Result(property = "caId",column = "caId"),
            @Result(property = "dates",column = "dates"),
            @Result(property = "numbers",column = "numbers"),
            @Result(property = "endDate",column = "endDate"),
            @Result(property = "sumMoney",column = "sumMoney"),
            @Result(property = "actMoney",column = "actMoney"),
            @Result(property = "price",column = "price"),
            @Result(property = "expenses",column = "expenses"),
            @Result(property = "conagen",column = "conagen"),
            @Result(property = "tranType",column = "tranType"),
            @Result(property = "tranStatus",column = "tranStatus")
    })
    public List<Tabase> QueryAll();

    /**
     * 按条件分页查询
     * @param start 开始行号
     * @param rows 每页行数
     * @param condition 查询条件
     * @return 交易数据对象集合
     */
    @ResultMap(value="tabaseMap")
    @Select("select * from (select a.*,rownum rn from (select * from taDataTable where 1=1 ${condition}) a where rownum<#{rows}) where rn>#{start}")
    public List<Tabase> findByPage(@Param("start") int start, @Param("rows") int rows, @Param("condition") String condition);

    /**
     *记录数
     * @return
     */
    /*@Select("<script>" +
            "select count(*) from taDataTable" +
            "<where>" +
            "<if test='fundId!=null'>" +
            " and fundId like '%${fundId}%'" +
            "</if>" +
            "</where>" +
            "</script>")*/
    @Select("select count(*) from taDataTable where 1=1 ${condition}")
    public int count(@Param("condition") String condition);


    /**
     * 查询券商数据
     * @return
     */
    @Select("select stockId,stockName,explain,notes from settingOfSecurities")
    public List<SettingOfSecurities> querySet();
}
